﻿using System.Data.Entity;

namespace UnitOfWork
{
    public class UnitOfWork<T> : IUnitOfWork where T : DbContext
    {
        private readonly IDatabaseFactory<T> _databaseFactory;
        private T _dataContext;

        public UnitOfWork(IDatabaseFactory<T> databaseFactory)
        {
            _databaseFactory = databaseFactory;
        }

        protected T DataContext
        {
            get { return _dataContext ?? (_dataContext = _databaseFactory.Get()); }
        }

        public void Commit()
        {
            DataContext.SaveChanges();
        }
    }
}
